package com.lzj.controller;

import com.lzj.entity.MeetingRoom;
import com.lzj.service.MeetingRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * <p>
 *
 * </p>
 *
 * @autor:lzj
 * @date:2022/3/1
 */
@Controller
public class MeetingRoomController {
    @Autowired
    private MeetingRoomService meetingRoomService;
    @RequestMapping("/meetingrooms")
    public String meetingrooms(Model model){
        model.addAttribute("mrs",meetingRoomService.getAllMr());
        return "meetingrooms";
    }

    @RequestMapping("/roomdetails/{roomid}")
    public String roomdetails(@PathVariable int roomid, Model model){
        model.addAttribute("mr",meetingRoomService.getMrById(roomid));
        return "roomdetails";
    }

    @RequestMapping("/updateRoom")
    public String updateRoom(MeetingRoom meetingRoom){
        int i = meetingRoomService.updateRoom(meetingRoom);
        if(i==1){
            return "redirect:/meetingrooms";
        }else{
            return "forward:/roomdetails/"+meetingRoom.getRoomid();
        }
    }

    @RequestMapping("/admin/addmeetingroom")
    public String addmeetingroom(){
        return "addmeetingroom";
    }

    @RequestMapping("/admin/doAddMr")
    public String doAddMr(MeetingRoom meetingRoom){
        int i = meetingRoomService.addMr(meetingRoom);
        return "redirect:/meetingrooms";
    }
}